// @ts-nocheck
<script lang="ts" setup>
import type { ColumnsType } from 'ant-design-vue/es/table'
import type { PoemProps } from './typing'
import type { FilterItem } from '~@/components/search-filter/typing'
import { getPoemList } from '~@/api/poem'
import AdvancedTable from '~@/components/search-table/index.vue'

const filters: FilterItem[] = [
  {
    type: 'input',
    field: 'name',
    label: '名称',
    placeholder: '请输入名称',
  },
  {
    type: 'select',
    field: 'status',
    label: '状态',
    placeholder: '请选择状态',
    options: [
      { label: '启用', value: 1 },
      { label: '禁用', value: 0 },
    ],
  },
  {
    type: 'datePicker',
    field: 'date',
    label: '日期',
    placeholder: '请选择日期',
  },
]

const columns: ColumnsType<PoemProps.TableProps> = [
  {
    title: '序号',
    dataIndex: 'index',
    key: 'index',
    width: 80,
    customRender: ({ index }) => index + 1,
  },
  {
    title: '名称',
    dataIndex: 'name',
    key: 'name',
    width: 120,
  },
  {
    title: '出生日期',
    dataIndex: 'birthday',
    key: 'birthday',
    width: 120,
  },
  {
    title: '朝代',
    dataIndex: 'dynasty',
    key: 'dynasty',
    width: 120,
  },
  {
    title: '简介',
    dataIndex: 'description',
    key: 'description',
    width: 120,
  },
  {
    title: '生平',
    dataIndex: 'life',
    key: 'life',
    width: 120,
  },
  {
    title: '性别',
    dataIndex: 'gender',
    key: 'gender',
    width: 120,
  },
  {
    title: 'wiki',
    dataIndex: 'wiki',
    key: 'wiki',
    width: 120,
  },

]
function handleSearch(values: Record<string, any>) {
  console.log('搜索条件：', values)
}

function handleReset() {
  console.log('重置表单')
}

function handleSuccess(res: any) {
  console.log('请求成功', res)
}

function handleSearchChange(e: any) {
  console.log('搜索条件变化', e)
}

function handleError(err: Error) {
  console.error('请求失败:', err.message)
}

// 显式暴露这些方法
defineExpose({
  handleSearch,
  handleReset,
})
</script>

<template>
  <AdvancedTable
    key="poem-table"
    :request="getPoemList"
    :columns="columns"
    :search-columns="filters"
    show-index
    immediate
    @success="handleSuccess"
    @error="handleError"
    @search-change="handleSearchChange"
  />
</template>
